
m=[[0,0,0],[0,0,0],[0,0,0]]
def main():
  turn=1
  board()
  while (True):
    turn=move(turn)
    if checkifwon()==False:
      break

def board():
  for y in range (3):
    for x in range(3):
      if ((x+1)%3)==0:
        print str(m[y][x]) + " |"
      else:
        print str(m[y][x]) + " |",

def move(turn):
  row=raw_input("Please Enter the Row (0-2):  ")
  col=raw_input("Please Enter the Column (0-2):  ")
  if m[int(row)][int(col)]>0:
    #if square is filled, repick move
    move(turn)
  else:
    if turn==1:
      m[int(row)][int(col)]=1
      turn=2
    else:
      m[int(row)][int(col)]=2
      turn=1
    board()
    return turn

def checkifwon():
  for x in range(3):
    #check horizontal
    if (m[x][0]==m[x][1]==m[x][2]) and (m[x][0]>0):
      print "%s's Win!" %m[x][0]
      return False
    elif (m[0][x]==m[1][x]==m[2][x]) and (m[2][x]>0):
      #checking vertical
      print "%s's Win!" %m[0][x]
      return False
  #Checks diagonals
  if (m[0][0]==m[1][1]==m[2][2]) and (m[2][2]>0):
    print "%s's Win!" %m[1][1]
    return False
  elif (m[2][0]==m[1][1]==m[0][2]) and (m[1][1]>0):
    print "%s's Win!" %m[1][1]
    return False


main()
#board()   
#move()

